﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Cemit.PolyServer
{
    public static class AppDomainSelectExtensions
    {
        /// <summary>选择所有继承自某泛型接口的类</summary>
        public static IEnumerable<Type> SelectTypeImplementsGenericInterface(this AppDomain domain, Type genericInterfaceType)
        {
            return domain.GetAssemblies()
                .SelectMany(SelectMessageHandle);

            IEnumerable<Type> SelectMessageHandle(Assembly a)
                => a.GetTypes().Where(
                   t => t.GetInterfaces()
                       .Any(type => type.IsGenericInterface(genericInterfaceType)));
        }
    }
}
